'use strict';
const Controller = require('egg').Controller;
const moment = require('moment');

class tranInfo extends Controller {
  async getTDate() {
    const { app, ctx } = this;

    const clients = app.mysql.get("file");

    let start = moment(new Date()).format('YYYY:MM:DD 00:00:00')
    let end = moment(new Date()).format('YYYY:MM:DD 23:59:59')

    let weekStart = moment(new Date(new Date().getTime() - 7 * 24 * 60 * 60 * 1000)).format('YYYY:MM:DD 00:00:00')
    let date1 = await clients.query('SELECT RSStationCode,RSStationName,PosX,PosY FROM rsstationinfo')
    let date2 = await clients.query('SELECT count(1)Week,RSStationCode FROM smokevehicle  WHERE  ImportDate between "' + weekStart + '" and "' + end + '" GROUP BY RSStationCode')
    let date3 = await clients.query('SELECT count(1)Today,RSStationCode FROM smokevehicle   WHERE ImportDate between "' + start + '" and "' + end + '" GROUP BY RSStationCode')
    let date4 = await clients.query('SELECT BGStation,count(1)CLLTotal FROM trafficflow GROUP BY BGStation')
    let date5 = await clients.query('SELECT count(1)HYCTotal,RSStationCode FROM smokevehicle  GROUP BY RSStationCode')

    let arr = []
    date1.forEach(e => {
      e.CLLTotal = 0
      e.Today = 0
      e.Week = 0
      e.HYCTotal = 0
      date2.forEach(i => {
        if (e.RSStationCode == i.RSStationCode) {
          e.Week = i.Week
        }
      })
      date3.forEach(k => {
        if (e.RSStationCode == k.RSStationCode) {
          e.Today = k.Today
        }
      })
      date4.forEach(j => {
        if (e.RSStationCode == j.BGStation) {
          e.CLLTotal = j.CLLTotal
        }
      })
      date5.forEach(m => {
        if (e.RSStationCode == m.RSStationCode) {
          e.HYCTotal = m.HYCTotal
        }
      })
      arr.push(e)
    })
    ctx.body = arr
  }

  async getTest() {
    let i = 100
    const { app, ctx } = this;
    await ctx.service.test.test1()
      .then(() => {

      })
      .finally(() => {
        console.log('finally')
      })
    if (i == 100) {
      console.log(9999)
    }
    ctx.body = {
      ad: "7327",
      atmos: "43.4",
      isHotting: false,
      isZeroing: false,
      k: "1.89",
      n: "0.00",
      ns: "0.00",
      pointFire: 1,
      round: "2653",
      stroke: 4,
      temp: "24.2",
      tempOil: "8.4",
      tempRoom: "76.0",
      tempSmoke: "31.0",
      tips: "",
      wet: "39.4",
      oilNum: 1.5,
      roundNum: 1.0
    }
  }
}
module.exports = tranInfo
